//路由鉴权:就是路由能不能被访问到权限设置->全局守卫完成
//引入路由器
import router from './router'
//@ts-ignore
import Nprogress from 'nprogress';
import 'nprogress/nprogress.css'
import { useUserStore } from './store/modules/user';
//进度条的加载小圆球不要
Nprogress.configure({ showSpinner: false });

const userStore=useUserStore()
const whilteList=['/home', '/hospital/register', '/hospital/detail', '/hospital/notice', '/hospital/close', '/hospital/search'];
//@ts-ignore
router.beforeEach((to,from,next)=>{
//  from
  Nprogress.start();
   //动态设置网页左上角的标题
   document.title = `尚医通-${to.meta.title}`;
   const token=userStore.userInfo.token
   if(token){
    next()
   }else {
    if(whilteList.includes(to.path)){
      next()
    }else {
      userStore.dialogTableVisible=true
      next({path:'/home',query: { redirect: to.fullPath }})
    }
   }
})

router.afterEach(()=>{
  Nprogress.done();
})